package com.faxsun.admin.web.domain;

import java.util.HashMap;
import java.util.Map;

import com.faxsun.model.BaseParam;
import com.faxsun.model.response.ApiResponse;
import com.faxsun.model.response.Response;

/**
 * 管理端显示Response的实体
 * 
 * @author zhaoteng.song@faxsun.com
 *
 */
public abstract class ResponseEntity {

	boolean isSucc=false;
	String msg;

	@SuppressWarnings("rawtypes")
	protected Response response;

	public boolean isSucc() {
		return isSucc;
	}

	public void setSucc(boolean isSucc) {
		this.isSucc = isSucc;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public ResponseEntity() {

	}

	public void buildFromResponse(
			@SuppressWarnings("rawtypes") Response response) {
		ApiResponse baseResponse = response.getBaseResponse();
		this.isSucc = baseResponse.getRetCode() == 200 ? true : false;
		this.response = response;

		this.msg = MESSAGES.get(new Integer(baseResponse.getRetCode()));
		
		buildFromResult((BaseParam) response.getResult());
	}

	protected abstract void buildFromResult(BaseParam result);

	protected static final Map<Integer, String> MESSAGES = new HashMap<Integer, String>();

	static {
		MESSAGES.put(new Integer(500), "服务器错误，请联系开发人员!");
		MESSAGES.put(new Integer(400), "发送请求错误，请联系开发人员!");
		MESSAGES.put(new Integer(401), "请求鉴权错误，请联系开发人员!");
		MESSAGES.put(new Integer(403), "请求支付接口失败，请联系开发人员!");
		MESSAGES.put(new Integer(404), "支付接口失效，请联系开发人员!");
		MESSAGES.put(new Integer(405), "请求参数错误，请联系开发人员!");
		MESSAGES.put(new Integer(406), "请求中业务参数错误，请联系开发人员!");
		MESSAGES.put(new Integer(407), "IP地址非法!");
		MESSAGES.put(new Integer(1001), "支付系统中不存在该订单!");
		MESSAGES.put(new Integer(1002), "订单状态错误!");
		MESSAGES.put(new Integer(1003), "退款金额错误，请核对后重试!");
		MESSAGES.put(new Integer(1004), "渠道接口错误，请联系开发人员!");
		MESSAGES.put(new Integer(1005), "订单已存在!");
		MESSAGES.put(new Integer(1006), "商户信息非法!");
		MESSAGES.put(new Integer(1007), "支付系统数据库操作失败!");
		MESSAGES.put(new Integer(1008), "买家不存在!");
		MESSAGES.put(new Integer(1009), "买家帐户不存在!");
		MESSAGES.put(new Integer(1010), "帐户余额不足!");
		MESSAGES.put(new Integer(1011), "卖家不存在!");
		MESSAGES.put(new Integer(1012), "卖家帐户不存在!");
		MESSAGES.put(new Integer(1013), "该订单在退款中!若该订单增加一笔新的退款，需等待当前退款处理完成");
	}
}
